package DAO;

import java.util.ArrayList;
import java.util.Date;

import org.hibernate.Criteria;
import org.hibernate.Session;
import to.Banco;
import util.HibernateUtil;

public class BancoDAO {

	public ArrayList<Banco> buscarTodos() throws Exception {
		ArrayList<Banco> listaRetorno = null;
		Session session = null;
		try {
			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Banco.class);
			listaRetorno = (ArrayList<Banco>) criteria.list();
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		} finally {
			session.close();
		}
		return listaRetorno;
	}

	public Banco buscarPorCodigo(Integer id) throws Exception {
		Banco retorno = new Banco();
		Session session = null;
		try {
			session = HibernateUtil.getSessionFactory().openSession();
			retorno = (Banco) session.get(Banco.class, id);
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		} finally {
			session.close();
		}
		return retorno;
	}
	public static void main(String[] args) {
		Date date = new Date();
		Date date2 = new Date();
	}

}
